
#include "StdAfx.h"

#include "HostApp.h"
#ifdef _WINDOWS
#include <windows.h>		// Header File For Windows
#endif
#include <gl\gl.h>			// Header File For The OpenGL32 Library
#include <gl\glut.h>		// Header File For The GLu32 Library
#include <string.h>
#include <stdio.h>

#include "Vlare.h"
#include "VlareImpl.h"
Vlare* pVlare;

void renderScene(void) {
	glClear(GL_COLOR_BUFFER_BIT);
	//glBegin(GL_TRIANGLES);
	//	glVertex3f(-0.5,-0.5,0.0);
	//	glVertex3f(0.5,0.0,0.0);
	//	glVertex3f(0.0,0.5,0.0);
	//glEnd();
	pVlare->RunFrame();
	glFlush();
}

void mouseMove(int x, int y)
{
	Vloat rx = (Vloat)x/(Vloat)glutGet(GLUT_WINDOW_WIDTH);
	Vloat ry = (Vloat)y/(Vloat)glutGet(GLUT_WINDOW_HEIGHT);
	pVlare->SetHook(pVlare->GetRoot(), VEM_POSITIONX, DynamicData((Vloat)rx));
	pVlare->SetHook(pVlare->GetRoot(), VEM_POSITIONY, DynamicData((Vloat)ry));
}
#ifdef _WINDOWS_MAIN
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR szCmdLine, INT argc)
{

	char **argv = new char*[argc];
	argv[0] = szCmdLine;
	for(int i=1 ; i<argc ; ++i)
	{
		argv[i] = strchr(argv[i-1], ' ');
		*argv[i]='\0';
		++argv[i];
	}
#else
void main(int argc, char **argv)
{
#endif
	VlareImpl vlare;
	pVlare = &vlare;
	VlareHashMap hm;
	hm.insert(VlarePair("Renderer", DynamicData("hw.OpenGL.standard.v001")));
	hm.insert(VlarePair("MemUse", DynamicData(0.9)));
	hm.insert(VlarePair("Detail", DynamicData(1.0)));
	vlare.Init(hm);
	ElementMemberMap map;
	vlare.AddElement(0x0, map);
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(320,320);
	glutCreateWindow("Vlare v0.1 using OpenGL");
	glutDisplayFunc(renderScene);
	glutIdleFunc(renderScene);
	glutMotionFunc(mouseMove);
	glutMainLoop();
	vlare.Free();
	delete [] argv;
}

HostApp::HostApp(void)
{
}

HostApp::~HostApp(void)
{
}
